
MACRO(CHECK_MACRO INCLUDE MAC VARIABLE)
	IF("${VARIABLE}" MATCHES "^${VARIABLE}$")

		SET(MACRO_CHECK_MACRO_DEFINITIONS 
			"-DCHECK_MACRO_EXISTS=${MAC} ${CMAKE_REQUIRED_FLAGS}")
		MESSAGE(STATUS "Looking for ${MAC}")

		IF(CMAKE_REQUIRED_LIBRARIES)
			SET(CHECK_MACRO_EXISTS_ADD_LIBRARIES
				"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
		ELSE(CMAKE_REQUIRED_LIBRARIES)
			SET(CHECK_MACRO_EXISTS_ADD_LIBRARIES)
		ENDIF(CMAKE_REQUIRED_LIBRARIES)

		SET(CHECK_MAC_INCLUDE_FILE_VAR ${INCLUDE})

		CONFIGURE_FILE(${CMAKE_MODULE_PATH}/CheckMacro.c.in
			${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckMacro.c IMMEDIATE)
		MESSAGE(STATUS "Looking for ${MAC} in ${INCLUDE}")

		TRY_COMPILE(${VARIABLE}
			${CMAKE_BINARY_DIR}
			${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckMacro.c
			COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
			CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_MACRO_DEFINITIONS}
			"${CHECK_MACRO_ADD_LIBRARIES}"
			OUTPUT_VARIABLE OUTPUT)

		IF (${VARIABLE})
			SET(${VARIABLE} 1 CACHE INTERNAL "Have macro ${MAC}")
			MESSAGE(STATUS "Looking for ${MAC} in ${INCLUDE} - found")
			FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 
				"Determining if ${MAC} exists passed with the following output:\n"
				"${OUTPUT}\n\n")
		ELSE (${VARIABLE})
			SET(${VARIABLE} "" CACHE INTERNAL "Have macro ${MAC}")
			MESSAGE(STATUS "Looking for ${MAC} in ${INCLUDE} - not found")
			FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 
				"Determining if the variable ${MAC} exists failed with the following output:\n"
				"${OUTPUT}\n\n")
		ENDIF (${VARIABLE})

	ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
ENDMACRO(CHECK_MACRO)

# vim:ts=4:sw=4

